package com.anxin.registerManagement.controller;

import com.anxin.registerManagement.bean.jo.PageJo;
import com.anxin.registerManagement.bean.persist.Permission;
import com.anxin.registerManagement.service.PermissionServcie;
import com.anxin.registerManagement.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author 叶前呈
 * @date 2022/1/31 13:26
 */
@Api(tags = "权限接口")
@RestController
@RequestMapping("/permissions")
public class PermissionController {

    // TODO:这里的权限应该是固定写死了的，给每个控制器都固定写死，通过权限组来获得相应权限
    private static final Logger logger = LoggerFactory.getLogger(PermissionController.class);

    @Autowired
    PermissionServcie permissionServcie;

    @ApiOperation("查询权限")
    @PostMapping("/search")
    public ResultUtil getPermissionList(PageJo pageJo) {
        return ResultUtil.success(permissionServcie.getPermissionList(pageJo));
    }

    @ApiOperation("添加权限")
    @PostMapping("/add")
    public ResultUtil addPermission(@Valid @RequestBody Permission permission) {
        return ResultUtil.success();
    }

    @ApiOperation("修改权限")
    @PostMapping("/update")
    public ResultUtil updatePermission(@Valid @RequestBody Permission permission) {
        return ResultUtil.success();
    }

    @ApiOperation("删除权限")
    @PostMapping("/delete")
    public ResultUtil deletePermission(@RequestParam("id") int id) {
        return ResultUtil.success();
    }

    @ApiOperation("获取所有权限")
    @GetMapping("/get")
    public ResultUtil getAllPermission() {
        return ResultUtil.success(permissionServcie.getAllPermission());
    }
}
